package com.fottas.adware.payment.controller;

import com.fottas.adware.common.api.CommonResult;
import com.fottas.adware.payment.model.vo.request.PayRequest;
import com.fottas.adware.payment.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "支付宝支付")
@Controller
@RequestMapping(value = "/aliPay")
public class AliPayController {
    @Autowired
    private PayService payService;

    @ApiOperation(value="app支付服务端")
    @PostMapping(value="/appPay")
    public CommonResult appPay(PayRequest request) {
        return CommonResult.success(payService.appPay(request));
    }

    /**
     * 电脑支付
     * @param request
     * @return
     */
    @ApiOperation(value="电脑支付")
    @PostMapping(value="pcPay")
    public String pcPay(PayRequest request) {
        return payService.aliPayPc(request);
    }

    /**
     * 支付宝异步回调
     * @param request
     * @return
     */
    @ApiOperation(value="支付宝支付回调(二维码、H5、网站)")
    @RequestMapping(value="/notify",method= RequestMethod.POST)
    public CommonResult notify(HttpServletRequest request) {
        payService.payNotify(request);
        return CommonResult.success();
    }
}
